package br.ufc.DAO.Implements;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.ufc.DAO.IProfessorDisciplina;
import br.ufc.si.model.ProfessorDisciplina;
import br.ufc.util.HibernateUtil;

public class ProfessorDisciplinaDAO implements IProfessorDisciplina {

	public void save(ProfessorDisciplina p) {
		Session sessao = HibernateUtil.getSession();

		Transaction txt = sessao.beginTransaction();

		try {
			sessao.save(p);
			txt.commit();
		} catch (Exception e) {
			txt.rollback();
		} finally {
			sessao.close();
		}

	}

	public void update(ProfessorDisciplina p) {
		Session sessao = HibernateUtil.getSession();

		Transaction txt = sessao.beginTransaction();

		try {
			sessao.update(p);
			txt.commit();
		} catch (Exception e) {
			txt.rollback();
		} finally {
			sessao.close();
		}

	}

	public void delete(ProfessorDisciplina p) {
		Session sessao = HibernateUtil.getSession();

		Transaction txt = sessao.beginTransaction();

		try {
			sessao.delete(p);
			txt.commit();
		} catch (Exception e) {
			txt.rollback();
		} finally {
			sessao.close();
		}
	}

}
